package xin.marcher.module.seller.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Repository;
import xin.marcher.module.seller.domain.entity.NationalCodeDO;
import xin.marcher.module.seller.domain.request.NationalCodeRequest;
import xin.marcher.module.seller.mapper.NationalCodeMapper;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 *
 */
@Repository
public class NationalCodeRepository {

    @Resource
    private NationalCodeMapper nationalCodeMapper;

    /**
     * 国标信息查询
     * 该接口不对外部暴露，只在初始化卖家树时调用，如果没有查到，说明国标SQL数据存在问题,直接抛出异常
     *
     * @param request
     * @return
     */
    public List<NationalCodeDO> queryNationalCode(NationalCodeRequest request) {
        // request的判空在调用该接口之前做处理，正常不会在别的地方调用改接口
        LambdaQueryWrapper<NationalCodeDO> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(Objects.nonNull(request.getId()), NationalCodeDO::getId, request.getId());
        queryWrapper.eq(Objects.nonNull(request.getLevelType()), NationalCodeDO::getLevelType, request.getLevelType());

        return nationalCodeMapper.selectList(queryWrapper);
    }
}
